package services

import (
	"gin-system/dao"
	"gin-system/models"
)

func GetAll(physical models.Physical) []models.Physical {
	physicalList := dao.GetPhysicalByPhysical(physical)
	return physicalList
}


func Del(id int) error {
	err := dao.Del(id)
	return err
}

func Update(physical models.Physical) error  {
	err := dao.Update(physical)
	return err
}

func Add(physical models.Physical) error {
	err := dao.Add(physical)
	return err
}

// GetAverage func GetPhysicalPricePhysical(id int) (error, models.Physical){
//	err, physical := dao.GetPhysicalById(id)
//	return err, physical
//}


func GetAverage() (error, models.StudentAverage) {
	err, data := dao.GetAllStudent()
	studentAverage := models.StudentAverage{}
	if err != nil {
		return err,studentAverage
	}
	for item := range data {
		studentAverage.Age += data[item].Age
		studentAverage.Height += data[item].Height
		studentAverage.Chest += data[item].Chest
		studentAverage.Weight += data[item].Weight
		studentAverage.StudentCount += 1
	}
	return err, studentAverage
}

func ExportFIle(physical models.Physical)  {
	physicalList :=GetAll(physical)
	Export(physicalList)
}



func GetConsecutiveMean() (error, []models.ConsecutiveMean) {
	err, data := dao.GetConsecutiveMean()
	if err != nil {
		return err,data
	}
	return err, data
}
